using System;
using System.Collections.Generic;
using System.Text;

namespace GPSCore
{
    /// <summary>
    /// Velocity is a Speed + Azimut + Elevation object
    /// </summary>
    public class Velocity : ICloneable, IComparable<Velocity>, IComparer<Velocity>, IEquatable<Velocity>
    {
        #region members

        /// <summary>
        /// protected Speed Object
        /// </summary>
        protected Speed _speed;

        /// <summary>
        /// protected Direction Object
        /// </summary>
        protected Direction _direction;

        #endregion

        #region constructors

        /// <summary>
        /// Build an hold Velocity object
        /// </summary>
        public Velocity()
        {
            _speed = new Speed(0.0);
            _direction = new Direction(0.0,0.0);
        }

        /// <summary>
        /// Build an hold Velocity object
        /// </summary>
        /// <param name="speed"></param>
        /// <param name="azimuth"></param>
        /// <param name="elevation"></param>
        public Velocity(double speed, double azimuth, double elevation)
        {
            _speed = new Speed(speed);
            _direction = new Direction(azimuth, elevation);
        }

        #endregion

        #region properties

        /// <summary>
        /// Speed
        /// </summary>
        public Speed Speed
        {
            get { return _speed; }
        }

        /// <summary>
        /// Azimuth
        /// </summary>
        public Azimuth Azimuth
        {
            get { return _direction.Azimuth; }
        }

        /// <summary>
        /// Elevation
        /// </summary>
        public Elevation Elevation
        {
            get { return _direction.Elevation; }
        }

        /// <summary>
        /// Direction
        /// </summary>
        public Direction Direction
        {
            get { return _direction; }
        }

        #endregion


        #region IComparable<Velocity> Members

        int IComparable<Velocity>.CompareTo(Velocity other)
        {
            if (this._speed.Value > other._speed.Value)
            {
                return 1;
            }
            else
            {
                if (this._speed.Value < other._speed.Value)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }

        #endregion

        #region IComparer<Velocity> Members

        int IComparer<Velocity>.Compare(Velocity x, Velocity y)
        {
            if (x._speed.Value > y._speed.Value)
            {
                return 1;
            }
            else
            {
                if (x._speed.Value < y._speed.Value)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }

        #endregion

        #region IEquatable<Velocity> Members

        bool IEquatable<Velocity>.Equals(Velocity other)
        {
            if ((this.Speed.Equals(other.Speed)) & (this.Direction.Equals(other.Direction)))
                return true;
            else
                return false;
        }

        #endregion

        #region ICloneable Members

        /// <summary>
        /// Clone a Velocity Object
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            Velocity _newValocity = new Velocity(this.Speed.Value, this.Azimuth.DecimalDegrees, this.Elevation.DecimalDegrees);

            return _newValocity;
        }

        #endregion
    }
}
